﻿/**
 * 生成水印背景
 * @param sfzh
 * @param xm
 * @param idName
 */
function watermark(c_sfzh,c_xm,c_div){
	var c_date=l_date();
	//1.添加临时canvas元素，以便生成对应图片：
	var w_width=300;
	var w_height=220;
	$("body").append('<canvas id="waterMarkerImg" width="'+w_width+'px" height="'+w_height+'px" style="display:none;"></canvas>');
	var c_canvas=document.getElementById("waterMarkerImg");
	if(!c_canvas.getContext){
		alert("浏览器不支持canvas");
	}else{
		c_context=c_canvas.getContext("2d");
		c_context.font="20px Microsoft YaHei";
		c_context.rotate(-20*Math.PI/100);
		c_context.fillStyle="rgba(6,6,6,0.1)";//实心字
		c_context.fillText(c_sfzh,-60,130);//倒数一个参数为纵轴坐标（距上边框），第二个参数为横轴坐标（距左边框）
		c_context.fillText(c_xm,-60,170);
		c_context.fillText(c_date,-60,210);
		//c_context.strokeStyle="rgba(0,0,0,0.1)";//空心字
		//c_context.strokeText("admin",-20,80);////空心字
		//2.将生成的图片设置为水印背景图片
		$("#"+c_div).css({"background-image":"url('"+c_context.canvas.toDataURL()+"')","background-repeat":"repeat"});
		//3.移除canvas元素
		$("#waterMarkerImg").remove();
	}
}
/**
 * 生成水印背景(参数可扩)
 * param:{"c_sfzh":"","c_xm":"","c_div":""}
 * @param sfzh
 * @param xm
 * @param idName
 */
function watermark_p(param){
	var c_sfzh=param.c_sfzh;
	var c_xm=param.c_xm;
	var c_div=param.c_div;
	var c_date=l_date();
	//1.添加临时canvas元素，以便生成对应图片
	var w_width=250;
	var w_height=180;
	$("body").append('<canvas id="waterMarkerImg" width="'+w_width+'px" height="'+w_height+'px" style="display:none;"></canvas>');
	var c_canvas=document.getElementById("waterMarkerImg");
	if(!c_canvas.getContext){
		alert("浏览器不支持canvas");
	}else{
		c_context=c_canvas.getContext("2d");
		c_context.font="22px Microsoft YaHei";
		c_context.rotate(-20*Math.PI/100);
		c_context.fillStyle="rgba(0,0,0,0.1)";
		c_context.fillText(c_sfzh,-20,80);
		c_context.fillText(c_xm,-30,120);
		c_context.fillText(c_date,-50,160);
		//c_context.strokeStyle="rgba(0,0,0,0.1)";//空心字
		//c_context.strokeText("admin",-20,80);////空心字
		//2.将生成的图片设置为水印背景图片
		$("#"+c_div).css({"background-image":"url('"+c_context.canvas.toDataURL()+"')","background-repeat":"repeat"});
		//3.移除canvas元素
		$("#waterMarkerImg").remove();
	}
}

/**
 * 获取系统时间
 */
function l_date(){
	var myDate=new Date();
	 var myyear = myDate.getFullYear();
	 var mymonth = myDate.getMonth();
	 var myweekday = myDate.getDate();
	 
	 var myhours = myDate.getHours();
	 var myminutes = myDate.getMinutes();
	 
	 mymonth=mymonth+1;
	 if(mymonth < 10){
			mymonth = "0"+mymonth;
		}
	 if(myweekday < 10){
	 	myweekday = "0"+myweekday;
	 }
	 if(myhours < 10){
	 	myhours = "0"+myhours;
	 }
	 if(myminutes < 10){
		 myminutes = "0"+myminutes;
	 }
	 return (myyear+"-"+mymonth+"-"+myweekday+" "+myhours+":"+myminutes);
}

